<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="common/tag.jsp"%>
<%@ include file="common/head.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>blocklyDemo</title>
<script src="${prc}/resources/script/blockly/blockly_compressed.js"></script>
<script src="${prc}/resources/script/blockly/blocks_compressed.js"></script>
<script src="${prc}/resources/script/blockly/javascript_compressed.js"></script>
<style type="text/css">
	html,body{margin: 0px;padding: 0px;height: 100%;width: 100% background-color: #fff;font-family: sans-serif;}
	#run{ position:fixed;right:0;width:100px;height:100px;z-index:999;background:rgba(0,0,0,0.5);line-height:100px; text-align:center;cursor: pointer;}
</style>
<script type="text/javascript" src="${prc}/resources/script/blockly/myBlockly.js"></script>

<script type="text/javascript">
 	$(function () { $('#myModal').on('show.bs.modal', function () {
			blockly.centerModals();
		});
	});
</script>
</head>
<body>
	<xml id="toolbox" style="display:none">
		<category id ="stock" name="财务"></category>
		<category id="strategy" name="策略"></category>
	</xml>
	<span id="run" data-toggle="modal" data-target="#myModal">RUN</span>
	<div id="blocklyDiv" style="height: 100%; width: 100%; background-color: #f4f4f4"></div>
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
	                 	&times;
	           		</button>
					<h4 class="modal-title" id="myModalLabel" style="color:#000000">得到的结果是</h4>
				</div>
				<div class="modal-body" id="modal-body">
					
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
	</div>
	<!-- /.modal -->
</body>
<script>
	blockly.initBlockly();
	var workspace = Blockly.inject('blocklyDiv', {media : 'resources/script/blockly/media/',toolbox : document.getElementById('toolbox')});
	$("#run").click(function(){
		 var code = Blockly.JavaScript.workspaceToCode(workspace);
			try {
				if(code!=null && code!=''){
					alert(code);
					blockly.findOperationResult(code);
				}else{
					alert("请选择后运算");
				}
			} catch (e) {
				alert(e)
			}
	});
	function onFirstComment(event) {
		 var code = Blockly.JavaScript.workspaceToCode(workspace);
		var desc = code.indexOf("~DESC");
		var asc = code.indexOf("~ASC");
		var scope = code.indexOf("min:");
		var DKBF = code.indexOf("~DKBF");
		var MACD = code.indexOf("~MACD");
		var BKBF = code.indexOf("~BKBF");
		if(desc!=-1){
			 document.getElementById("DESC").setAttribute("disabled",true);
			 document.getElementById("ASC").setAttribute("disabled",true);
			
		}else if(asc!=-1){
			document.getElementById("DESC").setAttribute("disabled",true);
			document.getElementById("ASC").setAttribute("disabled",true);
		}else{
			document.getElementById("DESC").setAttribute("disabled",false);
			document.getElementById("ASC").setAttribute("disabled",false);
		}
		if(scope!=-1){
			document.getElementById("scope").setAttribute("disabled",true);
		}else{
			document.getElementById("scope").setAttribute("disabled",false);
		}
		if(DKBF!=-1){
			document.getElementById("DKBF").setAttribute("disabled",true);
		}else{
			document.getElementById("DKBF").setAttribute("disabled",false);
		}
		if(MACD!=-1){
			document.getElementById("MACD").setAttribute("disabled",true);
		}else{
			document.getElementById("MACD").setAttribute("disabled",false);
		}
		if(BKBF!=-1){
			document.getElementById("BKBF").setAttribute("disabled",true);
		}else{
			document.getElementById("BKBF").setAttribute("disabled",false);
		}
	}
	workspace.addChangeListener(onFirstComment);
</script>

</html>